#!/usr/bin/env python

def make_start_command(host_config, command_list):
    
    sep = '/'
    
    if host_config['system'] == 'UNIX':
        
        sep = '/'
        
        if host_config['section'] == 'WAS':
            
            if host_config['type'] == 'SERVER':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'startServer.sh' + ' ' + host_config['server'])
            
            elif host_config['type'] == 'DMGR':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'startManager.sh')
            
            elif host_config['type'] == 'NODE':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'startNode.sh')
            
            elif host_config['type'] == 'S_SERVER':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'startServer.sh' + ' ' + host_config['server'] + ' -username ' + host_config['web_admin_user'] + ' -password ' + host_config['web_admin_pass'])
            
            elif host_config['type'] == 'S_DMGR':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'startManager.sh' + ' -username ' + host_config['web_admin_user'] + ' -password ' + host_config['web_admin_pass'])

            elif host_config['type'] == 'S_NODE':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'startNode.sh' + ' -username ' + host_config['web_admin_user'] + ' -password ' + host_config['web_admin_pass'])
                  
            
            else:
                
                print 'the WAS type: ' + host_config['type'] + 'is unknown.'
        
        elif host_config['section'] == 'TOMCAT':
            command_list.append(host_config['home'] + sep + 'bin' + sep + 'startup.sh')
            
        
        elif host_config['section'] == 'APACHE':
            
            command_list.append(host_config['home'] + sep + 'bin' + sep + 'apachectl' + ' ' + 'start')
            command_list.append('ps -ef|grep httpd')
            
        elif host_config['section'] == 'DB2':
            
            command_list.append('db2start')
        
        else:
            
            print 'the section type: ' + host_config['section'] + 'is unknown.'
    
    elif host_config['system'] == 'WIN':
        
        sep = '\\'

        if host_config['section'] == 'WAS':
            
            if host_config['type'] == 'SERVER':
                
                command_list.append('d:')
                command_list.append('cd ' + host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep)
                command_list.append('cd')
                #command_list.append('startServer ' + host_config['server'])
                #command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'startServer.bat' + ' ' + host_config['server'])
            
            elif host_config['type'] == 'DMGR':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'startManager.bat')
            
            elif host_config['type'] == 'NODE':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'startNode.bat')
            
            else:
                
                print 'the WAS type: ' + host_config['type'] + 'is unknown.'
        
    else:
        
        print 'the system type: ' + host_config['system'] + 'is unknown.'
    
    

def make_stop_command(host_config, command_list):
    
    sep = '/'
    
    if host_config['system'] == 'UNIX':
        
        sep = '/'
        
        if host_config['section'] == 'WAS':
            
            if host_config['type'] == 'SERVER':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'stopServer.sh' + ' ' + host_config['server'])
            
            elif host_config['type'] == 'DMGR':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'stopManager.sh')
            
            elif host_config['type'] == 'NODE':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'stopNode.sh')
            
            elif host_config['type'] == 'S_SERVER':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'stopServer.sh' + ' ' + host_config['server'] + ' -username ' + host_config['web_admin_user'] + ' -password ' + host_config['web_admin_pass'])
            
            elif host_config['type'] == 'S_DMGR':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'stopManager.sh' + ' -username ' + host_config['web_admin_user'] + ' -password ' + host_config['web_admin_pass'])

            elif host_config['type'] == 'S_NODE':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'stopNode.sh' + ' -username ' + host_config['web_admin_user'] + ' -password ' + host_config['web_admin_pass'])
                  
            else:
                
                print 'the WAS type: ' + host_config['type'] + 'is unknown.'
        
        elif host_config['section'] == 'TOMCAT':
            command_list.append(host_config['home']  + 'bin' + sep + 'shutdown.sh')
        
        elif host_config['section'] == 'APACHE':
            
            command_list.append(host_config['home']  + 'bin' + sep + 'apachectl' + ' ' + 'stop')
            command_list.append('ps -ef|grep httpd')
        
        elif host_config['section'] == 'DB2':
            
            command_list.append('db2stop force')
            
        
        else:
            
            print 'the section type: ' + host_config['section'] + 'is unknown.'
    
    elif host_config['system'] == 'WIN':
        
        sep = '\\'

        if host_config['section'] == 'WAS':
            
            if host_config['type'] == 'SERVER':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'stopServer.bat' + ' ' + host_config['server'])
            
            elif host_config['type'] == 'DMGR':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'stopManager.bat')
            
            elif host_config['type'] == 'NODE':
                
                command_list.append(host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'bin' + sep + 'stopNode.bat')
            
            else:
                
                print 'the WAS type: ' + host_config['type'] + 'is unknown.'
        
        
        elif host_config['section'] == 'APACHE':
            
            command_list.append(host_config['home'] + sep + 'bin' + sep + 'apachectl' + ' ' + 'stop')
            #command_list.append('ps -ef|grep httpd')
        
        else:
            
            print 'the section type: ' + host_config['section'] + 'is unknown.'        
        
            
    else:
        
        sep = '\\'
    
def make_command(host_config, action_type, command_list):
    
    sep = '/'
    
    if host_config['system'] == 'UNIX':     
    
        sep = '/'
    
        if host_config['section'] == 'WAS':
                    
            if host_config['type'] == 'SERVER' or host_config['type'] == 'S_SERVER':
                
                if action_type == 'DLOG':
                
                    command_list.append('rm -f ' + host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'logs' + sep + host_config['server'] + sep + '*.log')
                
                elif action_type == 'DTEMP':
                    
                    command_list.append('rm -rf ' + host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'temp')
                    command_list.append('mkdir ' + host_config['home']+'profiles'+ sep + host_config['name'] + sep + 'temp')
                
                else:
                    
                    print 'the action type: ' + action_type + 'is unknown'
            
            else:
                
               print 'the SERVER type: ' + host_config['type'] + 'is unknown.'  
        
        elif host_config['section'] == 'TOMCAT':

            if action_type == 'DLOG':
                
                command_list.append('rm -f ' + host_config['home']+'logs'+ sep + 'catalina.out')
                
            elif action_type == 'DTEMP':
                    
                command_list.append('rm -rf ' + host_config['home']+'work'+ sep + 'Standalone' + sep + 'localhost')
                command_list.append('mkdir ' + host_config['home']+'work'+ sep + 'Standalone' + sep + 'localhost')
                
            else:
                    
                print 'the action type: ' + action_type + 'is unknown'
        
        elif host_config['section'] == 'AIX':
            
            if action_type == 'GCONF':
                
                #command_list.append('prtconf > /tmp/conf.' + host_config['id'] + '.txt')
                command_list.append('prtconf')
            
            else:
                
                print 'the action type: ' + action_type + ' is unknown.'
            
    
    elif host_config['system'] == 'WIN':
        
        sep = '\\'
        
    else:
        
        print 'the section type: ' + host_config['system'] + 'is unknown.' 